<!-- 前台领料明细 -->
<template>
  <div>
    <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="false"
      height="auto"
      :dataSource="dataSource"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="onRowSelectChange"
    >
    </FilterTable>
  </div>
</template>

<script>
import { queryMaintainPicking } from '@/api/part/partOutbound/repairMaterials/index.js';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';
import { dictionary } from '@/utils/dictMixin';
import { arrayObjDeWeight, isAuthorized } from '@/utils/index';

export default {
  name: 'wxll_XXX',
  components: {
    // AddPanelRec
  },
  mixins: [dictionary],
  props: ['roNo'],
  data() {
    return {
      // 表单
      columns: this.createColumns(),
      dataSource: [],
      selectRows: [],
      tabaleList: []
      // isDels: []
    };
  },
  mounted() {
    // this.list.find(x => x.fieldName == 'receiver').initialValue = state.dict_llr[0].value; // 领料人默认第一个
    this.createBaseTable();
    this.getDealerUser();
    this.queryMaintainPicking();
  },
  methods: {
    createColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '备件代码',
          sorter: true,
          dataIndex: 'PART_NO',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件名称',
          sorter: true,
          dataIndex: 'PART_NAME',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '数量',
          sorter: true,
          dataIndex: 'PART_QUANTITY',
          width: 100,
          editable: false,
          editType: 'number',
          precision: 2,
          filter: true,
          filterType: 'number',
          summation: true
        },
        {
          title: '单位',
          sorter: true,
          dataIndex: 'UNIT_NAME',
          disabled: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单价',
          sorter: true,
          dataIndex: 'PART_SALES_PRICE',
          width: 100,
          editable: false,
          editType: 'number',
          precision: 2,
          filter: true,
          filterType: 'number',
          summation: true
        },
        {
          title: '不含税单价',
          sorter: true,
          dataIndex: 'PART_SALES_PRICE_NOTAX',
          precision: 2,
          filter: true,
          filterType: 'number',
          render: props => {
            props.row.PART_SALES_PRICE_NOTAX = (props.row.PART_SALES_PRICE / (1 + Number(0.13))).toFixed(2);
            return <span>{props.row.PART_SALES_PRICE_NOTAX}</span>;
          },
          summation: true
        },
        {
          title: '含税金额',
          sorter: true,
          dataIndex: 'PART_SALES_AMOUNT',
          precision: 2,
          filter: true,
          filterType: 'number',
          render: props => {
            props.row.PART_SALES_AMOUNT = (props.row.PART_SALES_PRICE * props.row.PART_QUANTITY).toFixed(2);
            return <span>{props.row.PART_SALES_AMOUNT}</span>;
          },
          summation: true
        },
        {
          title: '不含税金额',
          sorter: true,
          dataIndex: 'PART_SALES_AMOUNT_NOTAX',
          precision: 2,
          filter: true,
          filterType: 'number',
          render: props => {
            props.row.PART_SALES_AMOUNT_NOTAX = (props.row.PART_SALES_AMOUNT / (1 + Number(0.13))).toFixed(2);
            return <span>{props.row.PART_SALES_AMOUNT_NOTAX}</span>;
          },
          summation: true
        },
        {
          title: '领料人',
          dataIndex: 'RECEIVER',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '领料方式',
          sorter: true,
          dataIndex: 'PICK_TYPE',
          editable: false,
          editType: 'select',
          editItems: this.createDictList(8111),
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(8111)
        },
        {
          title: '渠道',
          sorter: true,
          dataIndex: 'BUY_REMARKS',
          filter: true,
          filterType: 'input'
        },
        {
          title: '收费区分',
          sorter: true,
          dataIndex: 'CHARGE_PARTITION_NAME',
          filter: true,
          filterType: 'input'
        },
        {
          title: '发料人',
          sorter: true,
          dataIndex: 'SENDER',
          editable: false,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '折扣率',
          width: 150,
          sorter: true,
          dataIndex: 'DISCOUNT',
          defaultEditable: true,
          editable: true,
          editType: 'number',
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '成本单价',
          sorter: true,
          dataIndex: 'PART_COST_PRICE',
          precision: 2,
          filter: true,
          filterType: 'number',
          hidden: !isAuthorized('1313', '13131005')
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        }
      ];
    },
    async queryMaintainPicking() {
      let params = {
        roNo: this.roNo,
        flag: 'A'
      };
      const res = await queryMaintainPicking(params);
      this.BaseTable.EXECUTE_INSERT(res.data);
    },
    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    onRowSelectChange(val) {
      // this.selectRows = val;
    },
    // 获取人员数据接口
    async getDealerUser() {
      const res = await getDealerUser();
      let data = arrayObjDeWeight(res.data, 'userId');
      this.columns.find(x => x.dataIndex == 'SERVICE_ADVISOR').editItems = this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').filterItems = this.columns.find(
        x => x.dataIndex == 'SENDER'
      ).editItems = this.columns.find(x => x.dataIndex === 'SENDER').filterItems = this.columns.find(x => x.dataIndex == 'RECEIVER').editItems = this.columns.find(
        x => x.dataIndex === 'RECEIVER'
      ).filterItems = data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
    }
  }
};
</script>

<style scoped>
.btn-wrap {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 60px;
}
</style>
